package org.gauth4me.core;

public class Util {
  private Util() {
    // no instantiation please
  }

  public static boolean arrayEquals(byte[] array1, byte[] array2) {
    boolean areEqual = (array1.length == array2.length);
    for (int i = 0; areEqual && i < array1.length; ++i) {
      if (array1[i] != array2[i]) {
        areEqual = false;
        break;
      }
    }
    return areEqual;
  }

  public static byte[] hexToBytes(String string) {
    final int len = string.length()/2;
    byte[] result = new byte[len];
    for (int i = 0, j = 0; i < len; ++i, j += 2) {
      result[i] = (byte) Integer.parseInt(string.substring(j, j + 2), 16);
    }
    return result;
  }
  
  public static String bytesToHex(byte[] bytes) {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < bytes.length; ++i) {
      buffer.append(Integer.toHexString(bytes[i]));
    }
    return buffer.toString();
  }
}
